package com.yzf.demo.demo.DesignPattren.PrototypePattern.Cloneable;


import java.util.ArrayList;
import java.util.List;

/**
 * Created by 于占峰 on 2020/3/16/016.
 * 实现cloneAble接口 也是浅克隆
 */
public class test {
    public static void main(String[] args) {
        DemoBean demoBean = new DemoBean();
        demoBean.setName("小明");
        demoBean.setAge(18);
        List<String> list = new ArrayList<>();
        list.add("打游戏");
        list.add("学习");
        list.add("扯犊子");
        demoBean.setHobbys(list);

        //使用beanUtil拷贝
        DemoBean copyDemo = demoBean.clone();
        List<String> lists = copyDemo.getHobbys();
        lists.add("新的爱好");
        copyDemo.setHobbys(lists);
        System.out.println("复制的对象" + copyDemo);
        System.out.println("原对象:" + demoBean);
        System.out.println(copyDemo == demoBean);
        System.out.println(copyDemo.getHobbys() == demoBean.getHobbys());
    }
}
